package com.smart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smart.model.domain.OperateRoleDO;
import com.smart.model.domain.OperateUserRoleDO;
import com.smart.model.request.OperateUserRoleRequest;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhanghong
 */
@Repository
public interface OperateUserRoleMapper extends BaseMapper<OperateUserRoleDO> {
    OperateUserRoleDO selectDOById(Long id);
    List<OperateUserRoleDO> selectDOList(OperateUserRoleDO operateUserRole);
    int insertDO(OperateUserRoleDO operateUserRole);
    int batchInsertDO(List<OperateUserRoleDO> operateUserRoleDOList);
    int updateDO(OperateUserRoleDO operateUserRole);
    int deleteDOById(Long id);
    int deleteDOByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from operate_user_role",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") OperateUserRoleRequest param);
    @Select({"<script>",
            "   select * from operate_user_role",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<OperateUserRoleDO> pageQuery(@Param("param") OperateUserRoleRequest param, @Param("limit") int limit, @Param("offset") long offset);

    @Delete("delete from operate_user_role where user_id=#{userId}")
    Integer deleteDOByUserId(Long userId);

    List<OperateRoleDO> listByUserId(Long userId);
}
